<style type="text/css">
div.files_body {
  margin-bottom: 5px;
}
div.files_body a:visited {
  color: purple;
}
div.files_body .file_menu {
  text-align: right;
  font-size: 10px;
}
</style>

<div id="contents_container">

<div id="contents_left">
  <% if @visitor_is_uploader %>
  <div class="box_space">
    <div class="box_space_title">メニュー</div>
    <div class="box_space_body">
      <%= icon_tag 'disk' -%> <%= generate_new_upload_menu @owner_symbol, @owner_name %>
    </div>
  </div><!-- box_space -->
  <% end %>
  <% form_tag({:action => 'share_file'}, {:id => :sharefile_search_form, :method => :get}) do %>
  <div class="box_space">
    <div class="box_space_title"><%= icon_tag 'find' -%>検索</div>
    <div class="box_space_body">
      <%= text_field_tag('keyword', params[:keyword], :size=>'10') %>
      <%= submit_tag '検索' %><br/>
      <%= check_box_tag("without_public", "true", params[:without_public]) %> 全体公開以外
    </div>
  </div><!-- box_space -->

  <div class="box_space">
    <div class="box_space_title"><%= icon_tag 'table_refresh' -%>表示順</div>
    <div class="box_space_body">
      <%= radio_button_tag("sort_type", "date", params[:sort_type] == "date", :id=>"sort_type_date") -%> 登録日順 <br/>
      <%= radio_button_tag("sort_type", "name", params[:sort_type] == "name", :id=>"sort_type_name") -%> ファイル名順
    </div>
  </div><!-- box_space -->
  <% end %>
  <div class="box_space">
    <div class="box_space_title"><%= icon_tag 'tag_blue' -%>タグ</div>
    <div class="box_space_body">
    <% for category in @categories %>
      <%= %(<b><span id="selected_tag">) if params[:category] == category -%>
      <a href="#" class="search_by_tag"><%=h "[#{category}]" %></a><br/>
      <%= %(</span></b>) if params[:category] == category -%>
    <% end %>
    </div>
    <div style="font-size:10px;text-align:right;"><a href="#" id="search_cancel">[選択をキャンセル]</a></div>
  </div><!-- box_space -->

</div><!-- contents_left -->

<div id="contents_right">

  <% if pages and pages.item_count > 0 -%>
    <div class="navi"><%= page_link pages -%></div>
    <div class="files_body">
      <% share_files.each do |share_file| %>
        <%= render :partial => 'share_file_box',
                   :locals => {:share_file => share_file,
                               :owner_name => @owner_name,
                               :visible_menu => true,
                               :visible_owner_link => false } %>
      <% end %>
    </div><!-- files_body -->

   <div class="navi"><%= page_link pages -%></div>
  <% end %>

</div><!-- contents_right -->

<div id="contents_bottom">
</div><!-- contents_bottom -->

</div><!-- contents_container -->

<script type="text/javascript">
$j(function(){
    $j('.clear_download_history_link')
    .click(function(){
        if (confirm('本当に削除しますか？')) {
            var shareFileId = this.id.split('_')[4];
            var clearDownloadUrl = "<%= url_for(:controller => 'share_file', :action => 'clear_download_history') -%>/";
            $j.ajax({
                type: "POST",
                data: { id:shareFileId },
                url: clearDownloadUrl,
                success: function(html){
                    alert('ダウンロード履歴の削除に成功しました');
                }
            });
        }
        return false;
    });

    $j('.search_by_tag')
    .click(function(){
        var hidden_tag = $j(document.createElement('input'))
        .attr({'value': $j(this).html().slice(1,-1), 'type': 'hidden', 'name': 'category'});

        $j('#sharefile_search_form')
        .append(hidden_tag)
        .submit();
        return false;
    });

    $j('#search_cancel')
    .click(function(){
        $j('#sharefile_search_form')
        .submit();
        return false;
    });
});
</script>
